package src.threadpool;

public class SingleThreadExecutor {
    public static void main(String[] args) {
        // 创建一个单线程的线程池
        java.util.concurrent.ExecutorService executorService = java.util.concurrent.Executors.newSingleThreadExecutor();

        // 提交任务
        for (int i = 0; i < 1000; i++) {
            executorService.execute(new Task());
        }

        // 关闭线程池
        executorService.shutdown();
    }

    static class Task implements Runnable {
        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName());
        }
    }
}
